{% extends "base.html" %}

{% block stylesheets %}
{% endblock %}

{% block content %}
<div class="jumbotron">
    <div class="container">
        <h1><b>{{ 'Register' if en else '用户注册' }}</b></h1>
        <h1></h1>
    </div>
</div>
<div class="container">
    <div class="row">
        <div class="col-md-6 offset-md-3">
            {% include "components/errors.html" %}

            {% if integrations.mlc() %}
            <a class="btn btn-secondary btn-lg btn-block" href="{{ url_for('auth.oauth_login') }}">
                {{ 'Login with Major League Cyber' if en else '使用Major League Cyber登陆' }}
            </a>
            <hr>
            {% endif %}

            {% with form = Forms.auth.RegistrationForm() %}
            {% from "macros/forms.html" import render_extra_fields %}
            <form method="post" accept-charset="utf-8" autocomplete="off" role="form">
                <div class="form-group">
                    <b>{{ 'Username' if en else form.name.label }}</b>
                    {{ form.name(class="form-control", value=name) }}
                    <small class="form-text text-muted">
                        {{ 'Your username on the site' if en else '你的平台昵称' }}
                    </small>
                </div>

                {% if Configs.sso_enabled == 0 %}
                <div class="form-group">
                    <b>{{ 'Real Name' if en else '真实姓名' }}</b>
                    {{ form.sname(class = "form-control", value = sname) }}
                    <small class="form-text text-muted">
                        {{ 'Never shown to the public' if en else '不会公开显示' }}
                    </small>
                </div>

                {% if Configs.register_uid == 1 %}
                <div class="form-group">
                    <b>{{ 'Student Number' if en else '学号' }}</b>
                    {{ form.sid(class = "form-control", value = sid) }}
                    <small class="form-text text-muted">
                        {{ 'Never shown to the public' if en else '不会公开显示' }}
                    </small>
                </div>
                {% endif %}
                {% endif %}

                <div class="form-group">
                    <b>{{ 'Email' if en else form.email.label }}</b>
                    {{ form.email(class="form-control", value=email) }}
                    <small class="form-text text-muted">
                        {{ 'Never shown to the public' if en else '不会公开显示' }}
                    </small>
                </div>
                <div class="form-group">
                    <b>{{ 'Password' if en else form.password.label }}</b>
                    {{ form.password(class="form-control", value=password) }}
                    <small class="form-text text-muted">
                        {{ 'Password used to log into your account' if en else '用来登陆的密码' }}
                    </small>
                </div>
                {{ form.nonce() }}

                {{ render_extra_fields(form.extra) }}

                <div class="row pt-3">
                    <div class="col-md-12">
                        {% if Configs.sso_enabled == 1 %}
                        {% if en %}
                        <input class="btn btn-md btn-primary btn-outlined float-right"
                               style="margin-left: 10px;margin-bottom: 10px;" id="sso" value="change SSO auth"
                               name="_sso" type="button" onclick="ssoregister()">
                        {% else %}
                        <input class="btn btn-md btn-primary btn-outlined float-right"
                               style="margin-left: 10px;margin-bottom: 10px;" id="sso" value="重新认证"
                               name="_sso" type="button" onclick="ssoregister()">
                        {% endif %}
                        {% endif %}
                        {% if en %}
                        {{ form.submit(class="btn btn-md btn-primary btn-outlined float-right",value="register") }}
                        {% else %}
                        {{ form.submit(class="btn btn-md btn-primary btn-outlined float-right",value="注册") }}
                        {% endif %}
                    </div>
                </div>

                {% if Configs.tos_or_privacy %}
                <div class="row pt-3">
                    <div class="col-md-12 text-center">
                        {% if en %}
                        <small class="text-muted text-center">
                            By registering, you agree to the
                            <a href="{{ Configs.privacy_link }}" rel="noopener" target="_blank">privacy policy</a>
                            and <a href="{{ Configs.tos_link }}" rel="noopener" target="_blank">terms of service</a>
                        </small>
                        {% else %}
                        <small class="text-muted text-center">
                            注册代表你已经同意
                            <a href="{{ Configs.privacy_link }}" rel="noopener" target="_blank">隐私政策</a>
                            和 <a href="{{ Configs.tos_link }}" rel="noopener" target="_blank">服务条款</a>
                        </small>
                        {% endif %}
                    </div>
                </div>
                {% endif %}
            </form>
            {% endwith %}
        </div>
    </div>
</div>

{% if Configs.sso_enabled == 1 %}
<script>
    function ssoregister() {
        var server = "{{ Configs.sso_server_address }}"
        if (window.location.href.includes("?")) {
            window.location.href = server + '?serviceUrl=' + encodeURIComponent(window.location.href + "&type=encryptedticket")
        } else {
            window.location.href = server + '?serviceUrl=' + encodeURIComponent(window.location.href + "?type=encryptedticket")
        }
    }
</script>
{% endif %}
{% endblock %}

{% block scripts %}
{% endblock %}
